package com.sz.common.base.utils;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * Package: com.sz.common.base.utils <br>
 * Function: TODO: ADD FUNCTION <br>
 * Author: Charles. <br>
 * Date: 2017-04-12 11:27:00.
 */
public class CollectionUtils extends org.springframework.util.CollectionUtils {
    /**
     * @param list
     * @param <T>
     * @return
     */
    public static <T> List<T> removeDuplication(List<T> list) {
        if (list != null && list.size() > 1) {
            List<T> listTemp = new ArrayList<>();
            for (T item : list) {
                if (!listTemp.contains(item)) {
                    listTemp.add(item);
                }
            }
            list.clear();
            list.addAll(listTemp);
        }
        return list;
    }


    public static <K, V> V getFirstOrNull(Map<K, V> map) {
        V obj = null;
        for (Map.Entry<K, V> entry : map.entrySet()) {
            obj = entry.getValue();
            if (obj != null) {
                break;
            }
        }
        return obj;
    }

}
